<?php
/**
 * Name
 * 2018/11/7
 * ╔═════╗                 ╔═╗ ╔═╗
 * ║ ╔═══╝                 ║ ║ ║ ║
 * ║ ╚═══╦══╦══╦═════╦═════╣ ╚═╝ ║
 * ╚═══╗ ║  ║  ║  ║  ║  ║  ╠═╗ ╔═╝
 * ╔═══╝ ║  ║  ║  ║  ║  ║  ║ ║ ║
 * ╚═════╩═════╩══╩══╩══╩══╝ ╚═╝
 */

namespace App\Http\Controllers\Admin;


use App\Http\Controllers\Controller;
use App\Http\Controllers\Admin\DateController;
use Illuminate\Support\Facades\Auth;
use Illuminate\Support\Facades\View;
use App\Models\User;
use App\Models\Goods;
use App\Models\Order;


class MainController extends Controller
{

    public function main()
    {
        if (!View::exists('Admin/main/index')) return view('404');
        $admin = Auth::guard('admin')->user();
        $day = date("Y-m-d");
        $lastday = date("Y-m-d",strtotime("-1 day"));
        $user['addusernum'] = User::where([["created_at",">",$lastday],['created_at',"<",$day]])->count();
        $user['addvipnum'] =User::where([["created_at",">",$lastday],['created_at',"<",$day],['user_type',2]])->count();
        $user['vipnum'] =User::where('user_type',2)->count();
        $user['usernum'] =User::count();

        $order['wait_pay'] = Order::where('status',"=",Order::STATUS_WAIT_PAY)->count();
        $order['wait_deliver'] = Order::where('status',"=",Order::STATUS_WAIT_DELIVER)->count();
        $order['wait_get'] = Order::where('status',"=",Order::STATUS_WAIT_GET)->count();
        $order['after'] = Order::where('status',"=",Order::STATUS_AFTER_ING)->count();

        $goods['open'] = Goods::where('status',"=",Goods::SALE_STATUS_OPEN)->count();
        $goods['out'] = Goods::where('stock',"=",0)->count();
        return view('Admin/main/index', compact('admin','user','order','goods'));
    }

    public function index()
    {
        if (View::exists('Admin/index')) {
            $user = Auth::guard('admin')->user();
            return view('Admin/layout',['user'=>$user]);
        } else {
            return 'View Not Found';
        }
    }

/*    public function error()
    {
        if (View::exists('Admin/layout')) {
            return view('Admin/layout',['error'=>1]);
        } else {
            return 'View Not Found';
        }
    }*/


    public function error()
    {
        if (View::exists('Admin/error')) {
            return view('Admin/error');
        } else {
            return 'View Not Found';
        }
    }



}